package com.braveman.im.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.braveman.im.R;
import com.braveman.im.bean.GroupOfDetailsBean;
import com.braveman.im.manager.ApiManager;
import com.braveman.im.ui.activity.message.EditAddGroupforActivity;
import com.braveman.im.ui.adapter.AddFriendsAdapter;
import com.braveman.im.ui.adapter.GroupOfDetailsAdapter;
import com.braveman.im.utils.UtilsStyle;
import com.ht.baselibs.retrofit.NetCallBack;
import com.ht.baselibs.ui.base.BaseActivity;
import com.ht.baselibs.utils.ActivityUtils;
import com.vondear.rxtools.RxBarTool;

import java.util.ArrayList;
import java.util.List;

import ezy.ui.layout.LoadingLayout;
import retrofit2.Call;
import retrofit2.Response;

/**
 * 作者 昊昊.
 * 年份 2017/10/26.
 * 时间 19:18.
 * 项目名称 hhkj.
 */

/**
 * 群详情
 */
public class GroupOfDetailsActivity extends BaseActivity {
    List<GroupOfDetailsBean.CoreMemberListBean> list = new ArrayList<>();
    GroupOfDetailsAdapter adapter;
    GroupOfDetailsBean gb;
    private TextView groupContent;
    private String groupId;
    private RecyclerView mLvActivityListMember;
    private View statusBar;
    private RelativeLayout rlUnderway;
    private RelativeLayout rlDaishenhe;
    private TextView tvTitle1;
    private TextView ivShenHeZhong;
    private RelativeLayout rlOver;
    private TextView tvTitle2;
    private TextView ivYiShenHe;
    private RelativeLayout rlActivityFlat;
    private TextView tvTitle3;
    private TextView ivYiShenHe2;
    private LinearLayout llActivityQrCode;
    private ImageView ivIconQrCode;
    private TextView tvShowLine;
    private LinearLayout llActivityPhoneFriends;
    private TextView tvActivityAddFriendsHint;
    private Button activityBtnOk;
    private String groupName;


    @Override
    protected void initTitleBar() {
        mTitleBarView.setTitleText("群主页").setLeftBtnIcon(R.mipmap.back_black).setOnLeftBtnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityUtils.finishActivity(GroupOfDetailsActivity.this);
            }
        });
    }

    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected void initIntentData(Intent callIntent) {
        groupId = callIntent.getStringExtra("groupId");
        // loadingLayout.showLoading();
    }

    @Override
    protected int initContentView() {
        UtilsStyle.setStatusBarMode(this, true);
        RxBarTool.FlymeSetStatusBarLightMode(getWindow(), true);
        RxBarTool.MIUISetStatusBarLightMode(getWindow(), true);
        return R.layout.activity_groupofdetails;

    }

    @Override
    protected void initChildView() {
        activityBtnOk = (Button) findViewById(R.id.activity_btn_ok);
        statusBar = (View) findViewById(R.id.status_bar);
        rlUnderway = (RelativeLayout) findViewById(R.id.rl_underway);
        rlDaishenhe = (RelativeLayout) findViewById(R.id.rl_daishenhe);
        tvTitle1 = (TextView) findViewById(R.id.tv_title1);
        ivShenHeZhong = (TextView) findViewById(R.id.iv_shen_he_zhong);
        rlOver = (RelativeLayout) findViewById(R.id.rl_over);
        tvTitle2 = (TextView) findViewById(R.id.tv_title2);
        ivYiShenHe = (TextView) findViewById(R.id.iv_yi_shen_he);
        rlActivityFlat = (RelativeLayout) findViewById(R.id.rl_activity_flat);
        tvTitle3 = (TextView) findViewById(R.id.tv_title3);
        ivYiShenHe2 = (TextView) findViewById(R.id.iv_yi_shen_he2);
        llActivityQrCode = (LinearLayout) findViewById(R.id.ll_activity_qr_code);
        ivIconQrCode = (ImageView) findViewById(R.id.iv_icon_qr_code);
        tvShowLine = (TextView) findViewById(R.id.tv_show_line);
        llActivityPhoneFriends = (LinearLayout) findViewById(R.id.ll_activity_phone_friends);
        tvActivityAddFriendsHint = (TextView) findViewById(R.id.tv_activity_add_friends_hint);

        groupContent = (TextView) findViewById(R.id.activity_group_centent);


        mLvActivityListMember = (RecyclerView) findViewById(R.id.lv_Activity_list_member);
        mLvActivityListMember.setLayoutManager(new LinearLayoutManager(this));
        adapter = new GroupOfDetailsAdapter(R.layout.item_detailsnotice, list);
        mLvActivityListMember.setAdapter(adapter);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.activity_btn_ok:
                Bundle bundle = new Bundle();
                bundle.putString("groupId", groupId);
                bundle.putString("groupName", groupName);
                ActivityUtils.startActivity(GroupOfDetailsActivity.this, EditAddGroupforActivity.class, bundle);
                break;
        }
    }

    @Override
    protected void initChildData() {
//        gb = new GroupOfDetailsBean();
        ApiManager.getApi().getGroupDetails(groupId).enqueue(new NetCallBack<GroupOfDetailsBean>() {
            @Override
            protected void onSuccess(Call<GroupOfDetailsBean> call, Response<GroupOfDetailsBean> response) {
                if (response != null) {
                    GroupOfDetailsBean groupOfDetailsBean = response.body();
                    groupName = groupOfDetailsBean.corpName;
                    groupContent.setText(groupOfDetailsBean.description);
                    if (list != null) {
                        list.clear();
                    }
                    list.addAll(groupOfDetailsBean.coreMemberList);
                    mLvActivityListMember.setAdapter(adapter);
                }
            }

        });
    }

    @Override
    protected void setChildViewListener() {
        findViewById(R.id.activity_btn_ok).setOnClickListener(this);
    }
}
